function outTT = f_process_trigger(eeg,chunkline,plot_triggers,Max_N)
% chunkline
% threshold = 0.4;
threshold = 0.1;
Interval = chunkline(1)-threshold;
trigger_start = chunkline(2);
% pause

TR = eeg.triggers;
newTR_time = TR(trigger_start).time; % remove triggers for the cues.

if TR(trigger_start+1).time - TR(trigger_start).time > threshold % noise is triggering
    NT_flat = [1];
else
    NT_flat = [0];
end
% NT_flat
original = TR(1).time;
for i_trial = 2:length(TR)
    original = [original TR(i_trial).time];
    if TR(i_trial).time - newTR_time(end) > Interval & length(newTR_time)< Max_N
        newTR_time = [newTR_time TR(i_trial).time]; %  add this one
        if i_trial < length(TR)
            if TR(i_trial+1).time - TR(i_trial).time > threshold
                NT_flat = [NT_flat 1];
            else
                NT_flat = [NT_flat 0];
            end
        end
    end
end


% display(['We read in ' num2str(length(newTR_time)) ' trials.']);
outTT.newTR_time = newTR_time;
outTT.NT_flat = NT_flat;
outTT.TR = original; % original triggers;
if plot_triggers == 1
    old_T = [];
    
    f5 = figure('position',[100 100 900 500]);
    figure(f5);
    for i_trial = 1:length(TR)
        old_T = [old_T TR(i_trial).time];
        plot(TR(i_trial).time,1,'b*');hold on;
    end
    for i_trial = 1:length(newTR_time)
        plot(newTR_time(i_trial),1,'or');hold on;
    end
        %ko9
%     pause
end
return